<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <meta name="author" content="Cassie">
  <!-- ie浏览器使用最新的edge引擎渲染页面 -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <meta name="keywords" content="Notes">
  <title>Cassie_Notesseven_note</title>
  <link rel="shortcut icon" href="../../images/logo.ico"/>
  <!-- link bootstrap -->
  <link rel="stylesheet" href="../../css/bootstrap.min.css"/>
  <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"/></script>
  <script src="../../js/bootstrap.min.js"></script> 
  <style>
    body{
    background-color: #f7f3ee!important;
    color: #948c76!important;
    
    /* #e0cc96 */
    }
    a{
    color: #948c76;
    }
    p{
        padding: 4px;
        font-size: 18px;
        border-radius: 4px;
    }
    kbd{
        letter-spacing: 1px;
        font-size: 15px;
    }
    pre{
        font-size: 14px;
        line-height: 1.8;
    }
    pre code{
        padding: 2px 4px!important;
        font-size: 90%!important;
        color: #c7254e!important;
        background-color: #f9f2f4!important;
        border-radius: 4px!important;
    }
    
  </style>
 </head>
 <body>
     <!-- exp：<code> </code>-->
   <div class="container">
<h1>委托:on</h1>
<p class="bg-primary">委托:on</p>
<pre>
exp：<code>
<div class="text-primary">HtmlCode:
< div class="box">
    < input type="" name="" class="clone">
    < button class="add">+< /button>
< /div>

< div class="row">
    < input type="" name="">
    < button class="remove">-< /button>
< /div></div><span class="text-primary">JavaScriptCode:</span>
// $('.box')
$('.add').click(function(){
    var row = $('.row').first().clone() 
    $(this).before(row) 
})
// 对于后面添加的元素，需要使用on事件
// 委托事件 将子元素的事件委托给父元素
// $('父元素').on('事件名称','子元素', function(){})
// off
$('.box').on( 'click', '.remove', function(){
    console.log($(this).index('.remove')) // 得到当前remove在remove数组元素里面的下标
    $(this).parent().remove()
})</code>
</pre>
</div>
  </body>
</html>